package com.sebiotec.driver.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;

import com.allen.library.base.BaseHttpUtil;
import com.allen.library.interceptor.Transformer;
import com.allen.library.observer.CommonObserver;
import com.sebiotec.basecommon.utils.constant.SjmConstant;
import com.sebiotec.basecommon.utils.language.LocalManageUtil;
import com.sebiotec.basecommon.utils.tools.ActivityTool;
import com.sebiotec.basecommon.utils.tools.SPUtils;
import com.sebiotec.driver.model.post.PostHistoryBean;
import com.sebiotec.driver.model.response.JobListResponse;
import com.sebiotec.driver.net.BookApiHelper;

import java.util.HashMap;

public class JobViewModel extends AndroidViewModel {
    public JobViewModel(@NonNull Application application) {
        super(application);
    }

    public MyJobDataCallBack mDataCallBack;

    //数据回调接口
    public interface MyJobDataCallBack<T> {
        void onDataSuccessCallBack(T t);
        void onDataFailCallBack(T t);
    }



    //获取UpComing数据
    public void   getJobData(String date, String Filter, int PageIndex, int PageSize, MyJobDataCallBack<Object> mDataCallBack){


        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(SjmConstant.LOGINID,""));
        map.put("Token", SPUtils.get(SjmConstant.TOKEN,""));
        map.put("Lang", LocalManageUtil.getSMJSetLanguageLocales(ActivityTool.getInstance().getLastActivity()));
        PostHistoryBean bean =new PostHistoryBean(date,Filter,PageIndex,PageSize);

        BookApiHelper.geRadomApi()
                .getJob(map,new BaseHttpUtil<PostHistoryBean>().convertVo2Json(bean))
                .compose(Transformer.<JobListResponse>switchSchedulers())
                .subscribe(new CommonObserver<JobListResponse>() {

                    @Override
                    protected String setTag() {
                        return "Job";
                    }

                    @Override
                    protected void onError(String errorMsg) {
                        mDataCallBack.onDataFailCallBack(errorMsg);
                    }

                    @Override
                    protected void onSuccess(JobListResponse s) {
                        //回调数据
                        mDataCallBack.onDataSuccessCallBack(s);
                    }
                });


    }






}
